package com.example.mybaitsdemo.controller;

import com.example.mybaitsdemo.bean.User;
import com.example.mybaitsdemo.dao.DBAccess;
import com.example.mybaitsdemo.dao.UserDao;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/User")
public class UserController {
    Logger logger=LoggerFactory.getLogger(UserController.class);
    @Autowired
    private UserDao userDao;

    /**
     * 自己写的mapper和userdao
     * @return
     */
    @GetMapping("/getUserList")
     public Map<String,Object> getUserList() {
         List<User> userList=userDao.queryUserList();
         Map<String,Object> map=new HashMap<>();
         map.put("code",0);
         map.put("msg","success");
         map.put("data",userList);
         logger.info("info :"+map);
         int i=0;
         try {
             i=1/0;
         }catch (Exception e){
             logger.error("i am  a  test  error "+e);
         }


//         logger.debug("i am  a test  debug ");
         logger.warn("i am  a test  warn ");

         return  map;
     }

    /**
     * generatorconfig生成的mapper和dao
     * @return
     */
    @GetMapping("/getUser")
    public Map<String,Object> getUser() {
        User user=userDao.queryUser(1);
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("msg","success");
        map.put("data",user);

        return  map;
    }
}
